# -*-coding: Utf-8 -*-
# @File : config .py
# author: Chimengmeng
# blog_url : https://www.cnblogs.com/dream-ze/
# Time：2023/10/9
import os
import sys
from pydantic_settings import BaseSettings
from utils import util

# flask 运行IP
SERVER_HOST = '127.0.0.1'

# flask 运行端口
SERVER_PORT = 6565

# 根目录 : LastProject
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

# 模版资源目录
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')

# 静态资源文件目录
STATIC_DIR = os.path.join(BASE_DIR, 'static')

# 数据库目录
DATABASE_DIR = os.path.join(BASE_DIR, 'database')

# CSV 文件保存目录
CSV_DATA_DIR = os.path.join(DATABASE_DIR, 'CsvData')

util.mkdir_file_name(BASE_DIR)
util.mkdir_file_name(TEMPLATE_DIR)
util.mkdir_file_name(STATIC_DIR)
util.mkdir_file_name(DATABASE_DIR)
util.mkdir_file_name(CSV_DATA_DIR)

# DEBUG 调试模式
DEBUG = True

# MySQL 数据库本地 IP
MYSQL_HOST = '127.0.0.1'

# MySQL 数据库本地 端口
MYSQL_PORT = 3306

# MySQL 数据库本地 用户名
MYSQL_USER = 'root'

# MySQL 数据库本地 密码
MYSQL_PASSWORD = '1314521'

# MySQL数据库存储库
MYSQL_DATABASE = 'house_info'

# MySQL数据库编码集
MYSQL_CHARSET = 'utf8'

# # Engine URL
# # ENGINE_URL = f"mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}?charset=utf8"
# ENGINE_URL = f"mysql+pymysql://root:1314521@127.0.0.1:3306/house_info?charset=utf8"
# print(ENGINE_URL)
# # 超过连接池大小外最多创建的连接
# MAX_OVERFLOW = 0,
#
# # Engine 连接池大小
# POOL_SIZE = 5,
#
# # Engine 池中没有线程最多等待的时间，否则报错
# POOL_TIMEOUT = 30,
#
# # Engine 多久之后对线程池中的线程进行一次连接的回收（重置）
# POOL_RECYCLE = -1


class BaseConfig(BaseSettings):
    BASE_DIR: str = BASE_DIR


class ServerConfig(BaseConfig):
    SERVER_HOST: str = SERVER_HOST
    SERVER_PORT: int = SERVER_PORT
    DEBUG: bool = DEBUG
    TEMPLATE_DIR: str = TEMPLATE_DIR
    STATIC_DIR: str = STATIC_DIR


class DatabaseConfig(BaseConfig):
    DATABASE_DIR: str = DATABASE_DIR
    CSV_DATA_DIR: str = CSV_DATA_DIR


class MysqlConfig(BaseConfig):
    MYSQL_HOST: str = MYSQL_HOST
    MYSQL_PORT: int = MYSQL_PORT
    MYSQL_USER: str = MYSQL_USER
    MYSQL_PASSWORD: str = MYSQL_PASSWORD
    MYSQL_DATABASE: str = MYSQL_DATABASE
    MYSQL_CHARSET: str = MYSQL_CHARSET


# class EngineConfig(BaseConfig):
#     ENGINE_URL = str(ENGINE_URL)
#     MAX_OVERFLOW: int = ENGINE_URL
#     POOL_SIZE: int = POOL_SIZE
#     POOL_TIMEOUT: int = POOL_TIMEOUT
#     POOL_RECYCLE: int = POOL_RECYCLE


# 创建配置对象
base_settings = BaseConfig()
server_settings = ServerConfig()
db_settings = DatabaseConfig()
mysql_settings = MysqlConfig()
# engine_settings = EngineConfig()
